#include "flow.hpp"
#define debug(x) ;//cout << #x << " " << x << endl;

void Flow::getSponsors(int clientID,vector<pair<int, int>>& receptor) {
    // for (int j = h[clientID + siteNum]; j; j = nx[j]) {
    //     if (to[j] <= siteNum && cap[j] > 0) {
    //         receptor.push_back(std::make_pair(to[j], cap[j]));
    //     }
    // }
    for(auto p:g[clientID+siteNum]){
        if(p.to <= siteNum && p.flow > 0){
            //std::cout << p.flow << "\n";
            receptor.push_back(std::make_pair(p.to, (int)p.flow));
        }
    }
}
Flow::Flow() {
}
void Flow::clear(){
    for(int i=0;i<=n;i++){
        dis[i] = cur[i] = gap[i] = ex[i] = 0;
        g[i].clear();
        buk[i].clear();
    }
    for(int i=n+1;i<=2*n;i++){
        buk[i].clear();
        gap[i] = 0;
    }
}
Flow::Flow(int siteNum, int clientNum) {
    this->siteNum = siteNum;
    this->clientNum = clientNum;
    this->S = this->SOURCE_PORT = this->siteNum + this->clientNum + 1;
    this->T = this->n = this->TARGET_PORT = this->SOURCE_PORT + 1;
    this->clear();
    debug(siteNum);
    debug(clientNum);
}

void Flow::addEdge(int siteID, int clientID, int _cap) {
    link(siteID, siteNum+clientID, _cap);
}

void Flow::addEdgeFromSource(int siteID, int _cap) {
    link(SOURCE_PORT, siteID, _cap);
}

void Flow::addEdgeToTarget(int clientID, int _cap) {
    link(siteNum+clientID, TARGET_PORT, _cap);
}

int Flow::getMaxFlow(){
    return (int)HLPP();
    }